package com.knowif.pojo;


import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.validation.constraints.NotEmpty;

import org.springframework.validation.annotation.Validated;

import com.fasterxml.jackson.annotation.JsonFormat;
@Validated
public class UserRedpacket {
	
    private Integer id;

    /**
     * 活动id
     */
	@NotEmpty(message="活动id不能为空")
    private Integer activityId;

    /**
     * 已分享红包金额
     */
    private Double sharedAmount;

    /**
     * 已分享人数
     */
    private Integer sharedNum;

    /**
     * 红包状态
     */
    private Integer status;

    /**
     * 用户id
     */
	@NotEmpty(message="用户id不能为空")
    private Integer userId;

    /**
     * 开始时间
     */
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date beginTime;

    /**
     * 结束时间
     */
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date endTime;

    /**
     * 使用时间
     */
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date usedTime;
    
    private RedpacketActivity redpacketActivity;
    
    private TUser tUser;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getActivityId() {
        return activityId;
    }

    public void setActivityId(Integer activityId) {
        this.activityId = activityId;
    }

    public Double getSharedAmount() {
        return sharedAmount;
    }

    public void setSharedAmount(Double sharedAmount) {
        this.sharedAmount = sharedAmount;
    }

    public Integer getSharedNum() {
        return sharedNum;
    }

    public void setSharedNum(Integer sharedNum) {
        this.sharedNum = sharedNum;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public Date getBeginTime() {
        return beginTime;
    }

    public void setBeginTime(Date beginTime) {
        this.beginTime = beginTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public Date getUsedTime() {
        return usedTime;
    }

    public void setUsedTime(Date usedTime) {
        this.usedTime = usedTime;
    }

	public RedpacketActivity getRedpacketActivity() {
		return redpacketActivity;
	}

	public void setRedpacketActivity(RedpacketActivity redpacketActivity) {
		this.redpacketActivity = redpacketActivity;
	}

	public TUser gettUser() {
		return tUser;
	}

	public void settUser(TUser tUser) {
		this.tUser = tUser;
	}
	
	
	public static Set<Integer> getUserIds(List<UserRedpacket> userRedpackets){
		if(userRedpackets == null || userRedpackets.isEmpty()){
			return new HashSet<Integer>();
		}
		Set<Integer> userIds = new HashSet<Integer>();
		for(UserRedpacket userRedpacket : userRedpackets){
			userIds.add(userRedpacket.getUserId());
		}
		return userIds;
	}
	
	public static void saveTuser(List<UserRedpacket> userRedPackets, List<TUser> tUsers) {
		for(UserRedpacket userRedpacket : userRedPackets){
			for(TUser tUser : tUsers){
				if(userRedpacket.getUserId() == tUser.getId()){
					userRedpacket.settUser(tUser);
				}
			}
		}
	}
	
	public static Set<Integer> getActivityIds(List<UserRedpacket> userRedPackets) {
		if(userRedPackets == null || userRedPackets.isEmpty()){
			return new HashSet<Integer>();
		}
		Set<Integer> activityIds = new HashSet<Integer>();
		for(UserRedpacket userRedpacket : userRedPackets){
			activityIds.add(userRedpacket.getActivityId());
		}
		return activityIds;
	}
	
	public static void saveRedpacketActivity(List<UserRedpacket> userRedPackets,
			List<RedpacketActivity> redpacketActivities) {
		if(userRedPackets == null || userRedPackets.isEmpty() ||redpacketActivities.isEmpty() || redpacketActivities == null ){
			return;
		}
		for(UserRedpacket userRedpacket : userRedPackets){
			for(RedpacketActivity redpacketActivity : redpacketActivities){
				if(userRedpacket.getActivityId() == redpacketActivity.getId()){
					userRedpacket.setRedpacketActivity(redpacketActivity);
				}
			}
		}
	}

	@Override
	public String toString() {
		return "UserRedpacket [id=" + id + ", activityId=" + activityId + ", sharedAmount=" + sharedAmount
				+ ", sharedNum=" + sharedNum + ", status=" + status + ", userId=" + userId + ", beginTime=" + beginTime
				+ ", endTime=" + endTime + ", usedTime=" + usedTime + ", redpacketActivity=" + redpacketActivity
				+ ", tUser=" + tUser + "]";
	}
	
}